JBoss Community Archive (Read Only)

Teiid 8.6

Embedded Guide

Embedded is a light-weight version of Teiid for use in any Java 6+ JRE. JBoss AS nor any application server is not required. This feature/kit are still evolving. Please consult the source examples and even unit tests utilizing the EmbeddedServer for a more complete guide as to its use.

Configuration

The primary way to configure Teiid Embedded is with the EmbeddedConfiguration class. It is provided to the EmbeddedServer at start-up and dictates much of the behavior of the embedded instance. From there the running server instance may have translators and VDBs deployed as needed.

The Classpath

Your application is responsible for having the appropriate classpath to utilize Teiid embedded. Typically you will want to include all of the jars from the embedded kit's lib directory. As needed by your deployment you should include jars from the optional folder along with any jars needed to provide source access. Hibernate core 4.1.6 or compatible is needed, but not included in the kit, if you wish to utilize the JDBC translator support for dependent joins using temp tables.

osgi

All Teiid jars can also be deployed as bundles in a OSGI container like Karaf. If you are working with Karaf, a feature.xml file is available in maven repo for your convenience. Usage pattern is below

  features:addurl mvn:org.jboss.teiid/teiid/8.6.0.Final/xml/karaf-features 
  features:install -v teiid

VDB Deployment

VDBs may be deployed in several ways in Embedded. Typically there is also no vdb versioning concept.

VDB Metadata API

VDB deployment can be done directly through VDB metadata objects that are the underpinning of vdb.xml deployment. Models (schemas) are deployed as a set to form a named vdb - see the EmbeddedServer.deployVDB method.

XML Deployment

Similar to a server based -vdb.xml deployment an InputStream may be given to a vdb.xml file - see the EmbeddedServer.deployVDB(InputStream) method.

Zip Deployment

Similar to a server based .vdb deployment a URL may be given to a zip file - see the EmbeddedServer.deployVDBZip method. The use of the zip lib for dependency loading is not enabled in Embedded.

Translators

Translators instances can be scoped to a VDB in AS using declarations in a vdb.xml file, however named instances are scoped to the entire EmbeddedServer and must be registered via the EmbeddedServer.addTranslator methods. A new server instance does not assume any translators are deployed and does not perform any sort of library scanning to find translators.

Sources

The Embedded Server will still attempt to lookup the given JNDI connection factory names via JNDI. In most non-container environments it is likely that no such bindings exist. In this case the Embedded Server instance must have ConnectionFactoryProvider instances manually registered using the EmbeddedServer.addConnectionFactoryProvider method. Note that the Embedded Server does not have built-in pooling logic, so to make better use of a standard java.sql.DataSource or to enable proper use of javax.sql.XADataSource you must first configure the instance via a third-party connection pool.

Example Deployment
EmbeddedServer es = new EmbeddedServer();
EmbeddedConfiguration ec = new EmbeddedConfiguration();
//set any configuration properties
ec.setUseDisk(false);
es.start(ec);
//example of adding a translator by class - this will make a default instance available with the default name of oracle
es.addTranslator(OracleExecutionFactory.class);

//add a translator by instance - this is functionally equivalent to using a vdb.xml translator override
OracleExecutionFactory oef = new OracleExecutionFactory();
//configure and start the instance
oef.setDatabaseVersion("11.0");
oef.start();
es.addTranslator("my-oracle", oef);

//add a connection factory provider if needed
//the default is to perform a jndi lookup of the datasource names given
//however out of a container you will likely need to manually inject the necessary connection factory

ConnectionFactoryProvider<DataSource> cfp = new EmbeddedServer.SimpleConnectionFactoryProvider<DataSource>(...);
es.addConnectionFactoryProvider("ora-ds", cfp);

//add a vdb

//physical model
ModelMetaData mmd = new ModelMetaData();
mmd.setName("my-schema");
mmd.addSourceMapping("my-schema", "my-oracle", "ora-ds");

//virtual model
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("virt");
mmd1.setModelType(Type.VIRTUAL);
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText("create view \"my-view\" OPTIONS (UPDATABLE 'true') as select * from \"my-table\"");

es.deployVDB("test", mmd, mmd1);

Access from client applications

Typically when Teiid is deployed as Embedded Server, and if your end user application is also deployed in the same virtual machine as the Teiid Embedded, you can use "Local JDBC Connection", to access to your virtual database. For example:

  EmbeddedServer es = ...
  Driver driver = es.getDriver();
  Connection conn = driver.getConnection("jdbc:teiid:<vdb-name>");
  // do work with conn; create statement and execute it
  conn.close();

This is the most efficient method as it does not impose any serialization of objects.

If your client application is deployed in remote VM, or your client application is not a JAVA based application then accesses to the Teiid Embedded is not possible through above mechanism. In those situations, you need to open a socket based connection from remote client application to the Embedded Teiid Server. By default, when you start the Embedded Teiid Sever it does not add any capabilities to accept remote JDBC/ODBC based connections. If you would like to expose the functionality to accept remote JDBC/ODBC connection requests, then configure necessary "transports" during the initialization of the Teiid Embedded Server. The example below shows a sample code to enable a ODBC transport

  EmbeddedServer es = new EmbeddedServer()
  SocketConfiguration s = new SocketConfiguration();
  s.setBindAddress("<host-name>");
  s.setPortNumber(35432);
  s.setProtocol(WireProtocol.pg);
  EmbeddedConfiguration config = new EmbeddedConfiguration();
  config.addTransport(s);
  es.start(config);

if you want to add a JDBC transport, follow the instructions above, however set the protocol to "WireProtocol.teiid" and choose a different port number. Once the above server is running, you can use same instructions as Teiid Server to access Embedded Teiid Server from remote client application. Note that you can add multiple transports to single Embedded Server instance, to expose different transports.

Transactions

Transaction processing requires setting the TransactionManager in the EmbeddedConfiguration used to start the EmbeddedServer. A client facing javax.sql.DataSource is not provided for embedded. However the usage of provided java.sql.Driver should be sufficient as the embedded server is by default able to detect thread bound transactions and appropriately propagate the transaction to threads launched as part of request processing. The usage of local connections is also permitted.

Other Differences Between Teiid Embedded and an AS Deployment

  • There is no default JDBC/ODBC socket transport in embedded. You are expected to obtain a Driver connection via the EmbeddedServer.getDriver method. If you want remote JDBC/ODBC transport see above on how to add a transport.

  • A MetadataRepository is scoped to a VDB in AS, but is scoped to the entire EmbeddedServer instance and must be registered via the EmbeddedServer.addMetadataRepository method.

  • MDC logging values are not available as Java logging lacks the concept of a mapped diagnostic context.

  • Designer index file based metadata is not supported.

  • Translator overrides in vdb.xml files is not supported.

JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 12:50:12 UTC, last content change 2013-09-23 15:52:41 UTC.